from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import time

driver = webdriver.Edge()

# 单击鼠标左键
driver.get("https://www.baidu.com/")
driver.maximize_window()
element = driver.find_element(By.ID, 's-top-loginbtn')      # 定位到“登录”按钮对应的元素
ActionChains(driver).click(element).perform()        # 左键单击登录按钮

# 鼠标指针悬停
driver.get("http://www.itcast.cn/")
element = driver.find_element(By.CLASS_NAME, 'a_gd')        # 定位到JavaEE对应的元素
ActionChains(driver).move_to_element(element).perform()         # 移动到指定位置后悬停

# 鼠标拖拽
driver.get("https://portal.fuyunfeng.top/plugins_v2/index.html#/slider-verify-example")
element = driver.find_element(By.XPATH, "//div[@id='circle']")      # 定位元素
action = ActionChains(driver)       # 创建鼠标移动对象
action.click_and_hold(element)      # 按住鼠标左键
action.drag_and_drop_by_offset(element, 100, 0)     # 向右拖拽100px
time.sleep(2)       # 等待2秒
action.perform()
